/**
 * 
 */
package org.gas.barapraja.db.entity;

import java.io.Serializable;
import java.util.Date;

/**
 * @author gilang
 *
 */
public class Token implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -4060034929135080822L;
	
	private Long id;
	
	private String tokenId;
		
	private Integer tokenValue;
	
	private Integer tokenUsed;
	
	private Integer tokenBalance;
	
	private Date tokenExpire;
	
	private Account account;
	

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the account
	 */
	
	
	public String getTokenId() {
		return tokenId;
	}

	
	public void setTokenId(String tokenId) {
		this.tokenId = tokenId;
	}

	
	public Account getAccount() {
		return account;
	}

	
	/**
	 * @param account the account to set
	 */
	public void setAccount(Account account) {
		this.account = account;
	}

	/**
	 * @return the tokenValue
	 */
	public Integer getTokenValue() {
		return tokenValue;
	}

	/**
	 * @param tokenValue the tokenValue to set
	 */
	public void setTokenValue(Integer tokenValue) {
		this.tokenValue = tokenValue;
	}
	
	public Integer getTokenUsed() {
		return tokenUsed;
	}

	public void setTokenUsed(Integer tokenUsed) {
		this.tokenUsed = tokenUsed;
	}

	public Integer getTokenBalance() {
		return tokenBalance;
	}

	public void setTokenBalance(Integer tokenBalance) {
		tokenBalance = tokenValue - tokenUsed;
		this.tokenBalance = tokenBalance;
	}
	
	public Date getTokenExpire() {
		return tokenExpire;
	}

	public void setTokenExpire(Date tokenExpire) {
		this.tokenExpire = tokenExpire;
	}
	

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((account == null) ? 0 : account.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result
				+ ((tokenBalance == null) ? 0 : tokenBalance.hashCode());
		result = prime * result
				+ ((tokenExpire == null) ? 0 : tokenExpire.hashCode());
		result = prime * result + ((tokenId == null) ? 0 : tokenId.hashCode());
		result = prime * result
				+ ((tokenUsed == null) ? 0 : tokenUsed.hashCode());
		result = prime * result
				+ ((tokenValue == null) ? 0 : tokenValue.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Token other = (Token) obj;
		if (account == null) {
			if (other.account != null)
				return false;
		} else if (!account.equals(other.account))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (tokenBalance == null) {
			if (other.tokenBalance != null)
				return false;
		} else if (!tokenBalance.equals(other.tokenBalance))
			return false;
		if (tokenExpire == null) {
			if (other.tokenExpire != null)
				return false;
		} else if (!tokenExpire.equals(other.tokenExpire))
			return false;
		if (tokenId == null) {
			if (other.tokenId != null)
				return false;
		} else if (!tokenId.equals(other.tokenId))
			return false;
		if (tokenUsed == null) {
			if (other.tokenUsed != null)
				return false;
		} else if (!tokenUsed.equals(other.tokenUsed))
			return false;
		if (tokenValue == null) {
			if (other.tokenValue != null)
				return false;
		} else if (!tokenValue.equals(other.tokenValue))
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		return "Token [id=" + id + ", tokenId=" + tokenId + ", tokenValue="
				+ tokenValue + ", tokenUsed=" + tokenUsed + ", tokenBalance="
				+ tokenBalance + ", tokenExpire=" + tokenExpire + ", account="
				+ account + "]";
	}	
	
}
